package com.rd.student.ruanjian.class4.lichunquan.Text03;

import com.sun.org.apache.xpath.internal.operations.String;


public class T3_Test05 {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Thread1());
        Thread t2 = new Thread(new Thread2());
        Print p = new Print(t1,t2);


    }
}

class Print {
    Thread t1;
    Thread t2;
    int i = 0;
    char a = 'A' - 1;
    StringBuilder stringBuilder = new StringBuilder();
    Print(){}
    public Print(Thread t1, Thread t2) {
        this.t1 = t1;
        this.t2 = t2;
    }

    public void printT1() {
        synchronized (this) {
            while (i < 53) {
                stringBuilder.append(i);
                try {
                    t1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                t2.notify();
            }
        }
    }

    public void printT2() {
        synchronized (this) {
            while(a<='Z'){
                stringBuilder.append(a);
                try {
                    t2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                t1.notify();
            }
        }
    }
    public void getResult(){
        System.out.println(stringBuilder);
    }
}

class Thread1 extends Print implements Runnable {
    @Override
    public void run() {
        super.printT1();
    }
}

class Thread2 extends Print implements Runnable {


    @Override
    public void run() {
        super.printT2();
    }
}